import React from 'react';
import { Card } from 'antd';
import { PageContainer } from '@ant-design/pro-layout';
import ProTable from '@ant-design/pro-table';
import { indexColumns as columns } from './columns';
import { pageList } from '@/services/CheckBook';
import Search from './components/IndexSearch'

class Check extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      params: {}
    }
    this.proTableRef = React.createRef();
  }

  /* 获取table列表数据 */
  getPageList = async (currentParams) => {
    try {
      const params = this.state.params;
      const res = await pageList({
        ...params,
        ...currentParams
      })
      this.setState({ dataSource: res.data })
      return {
        success: true,
        data: res.data,
        total: res.totalSize
      }
    } catch (e) {
      console.error(e)
    }
  }

  /* 监听查询事件 */
  onSearch = (data) => {
    const params = this.state.params;
    this.setState({ params: {...params, ...data} });
    this.proTableRef.current.reload();
  }

  /* 刷新事件 */
  onReload = () => {
    this.setState({ params: {} });
    this.proTableRef.current.reload();
  }

  render() {
    const proTableRef = this.proTableRef;
    return (
      <PageContainer>
        <Card
          bodyStyle={{ paddingTop: 30, paddingBottom: 0 }}
          title="清查任务"
          bordered={false}>
          <Search search={this.onSearch} reset={this.onReload} />
        </Card>
        <ProTable
          actionRef={proTableRef}
          rowKey='id'
          search={false}
          columns={columns}
          request={this.getPageList} />
      </PageContainer>
    )
  }
}

export default Check